package ar.com.solidussource.howmuchmobile.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import ar.com.solidussource.howmuchmobile.R;
import ar.com.solidussource.howmuchmobile.activities.generic.BaseActivity;
import ar.com.solidussource.howmuchmobile.activities.maps.HowMuchMapActivity;
import ar.com.solidussource.howmuchmobile.activities.generic.MenuActivity;
import ar.com.solidussource.howmuchmobile.common.entities.Product;
import ar.com.solidussource.howmuchmobile.common.exception.ServiceException;

/**
 * Created with IntelliJ IDEA.
 * User: FT31270775
 * Date: 06/11/12
 * Time: 11:54
 * To change this template use File | Settings | File Templates.
 */
public class MainActivity extends BaseActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = (View) inflater.inflate(R.layout.main_menu, null);

        ListView lstOpciones = (ListView)v.findViewById(R.id.menuList);

        lstOpciones.setAdapter(new MainMenuArrayAdapter(this, serviceCall()));

        setContent(v);
    }

    private Product[] serviceCall() {
        Product[] data = new Product[2];

        Product product1 = new Product();
        product1.setName("Example1");
        Product product2 = new Product();
        product2.setName("Example2");

        data[0] = product1;
        data[1] = product2;

        return data;
    }

    class MainMenuArrayAdapter extends ArrayAdapter<Product> {

        Activity context;
        Product[] products;

        MainMenuArrayAdapter(Activity context, Product[] data) {
            super(context, R.layout.main_menu_row, data);
            this.context = context;
            this.products = data;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = context.getLayoutInflater();
            View item = inflater.inflate(R.layout.main_menu_row, null);

            TextView lblTitulo = (TextView) item.findViewById(R.id.mainMenu);
            lblTitulo.setText(products[position].getName());

            return(item);
        }

    }
}